﻿using UnityEngine;
using System.Collections;

public class EnemyControllerTerrestre1 : MonoBehaviour {
	
	public bool needToPuli;
	
	// Use this for initialization
	void Start () {
		
		StartCoroutine(puliEnemy());
		Destroy(this.gameObject , 15f);
		this.transform.position = new Vector3(this.transform.position.x -0.1f, -1.46f, this.transform.position.z);
	}
	
	// Update is called once per frame
	void Update () {
		
		this.transform.position = new Vector3(this.transform.position.x -0.1f, this.transform.position.y, this.transform.position.z);
	
	}
	
	
	void OnTriggerEnter (Collider other){
		
		if(other.gameObject.tag == "Player"){
			
			Destroy (this.gameObject);
		}
	}
	
	IEnumerator puliEnemy(){


		int rand = Random.Range(0,100);

		if(rand < 50){

			needToPuli = true;


		}else{
			needToPuli = false;
		}


		if(needToPuli == true){

			this.gameObject.rigidbody.AddForce(transform.up * 300);

		}else{

		}

		yield return new WaitForSeconds(3f);


		StartCoroutine(puliEnemy());


	}


}
